package net.entelijan.cobean.examples.lit;

import java.awt.event.ActionEvent;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

import net.entelijan.cobean.examples.data.literature.endpoint.LitBook;
import net.entelijan.cobean.examples.data.literature.endpoint.WsLitService;
import net.entelijan.cobean.examples.util.ExamplesUtil;
import net.entelijan.config.CobeanConfigFactory;
import net.entelijan.config.ICobeanConfig;

public class EditBookDialogController {
	
	private LitBook model;
	private EditAuthorDialog view;
	private WsLitService litService;

	@SuppressWarnings
	public EditBookDialogController(EditAuthorDialog view,
			LitBook model, WsLitService litService) {
		
		this.model = model;
		this.view = view;
		this.litService = litService;

		ICobeanConfig cfg = CobeanConfigFactory.createConfig();
		model = cfg.bind(model, view, null);

		view.getOkButton().addActionListener(new DefaultActionListener("Confirm Edit Book") {

			@Override
			public void actionPerformedIntern(ActionEvent e) {
				EditBookDialogController.this.litService.saveBook(EditBookDialogController.this.model);
				ExamplesUtil.disposeRoot(e);
			}
		});
		view.getCancelButton().addActionListener(new DefaultActionListener("Cancel Edit Book") {

			@Override
			public void actionPerformedIntern(ActionEvent e) {
				ExamplesUtil.disposeRoot(e);
			}
		});
	}

	public void open() {
		view.setVisible(true);
	}

}
